package com.itheima.a09regexdemo;

public class RegexDemo5 {
    public static void main(String[] args) {
        //判断一个字符串的开始部分和结束部分是否一致  只考虑一个字符
        //举例：a123a   b456b  17891  &abc&  a123b(false)
        String regex1 = "(.).+\\1";
        System.out.println("a123a".matches(regex1));
        System.out.println("b456b".matches(regex1));
        System.out.println("17891".matches(regex1));
        System.out.println("&abc&".matches(regex1));
        System.out.println("a123b(false)".matches(regex1));

        System.out.println("--------------------");
        //判断一个字符串的开始部分和结束部分是否一致  考虑多个字符
        String regex2 = "(.+).+\\1";
        System.out.println("a123a".matches(regex2));
        System.out.println("b456b".matches(regex2));
        System.out.println("17891".matches(regex2));
        System.out.println("&abc&".matches(regex2));
        System.out.println("a123b(false)".matches(regex2));


        System.out.println("-------------------------");
        //举例：a123a   b456b  17891  &abc&  a123b(false)
        //判断一个字符串的开始部分和结束部分是否一致  开始部分内部每个字符也需要保持一致
        String regex3 = "((.)\\2*)+\\1";
        System.out.println("aaa123aaa".matches(regex2));
        System.out.println("bbb456bbb".matches(regex2));
        System.out.println("111789111".matches(regex2));
        System.out.println("&&&abc&&&".matches(regex2));
        System.out.println("aaa123aab".matches(regex2));
    }
}
